﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

 

namespace deneme
{
    public partial class AdminForm : Form
    {
        SqlConnection con = new SqlConnection(ClassSqlConnection.ConnectionString);
        ClassShowDataGridView csdgw2 = new ClassShowDataGridView();
        ClassFillComboBox cfcb = new ClassFillComboBox();

        double tk1;
        double vagon1 = 100;
        double vagon2 = 100;
        double vagon3 = 100;
        double vagon4 = 100;
        double vagon5 = 100;
        double vagon6 = 100;
        double vagon7 = 100;
        double vagon8 = 100;
        double vagon9 = 100;
        double vagon10 = 100;
        int vagonSayisi=0;

        public AdminForm()
        {
            InitializeComponent();
        }
        
        private void button1_Click(object sender, EventArgs e)
        {

        }
        public void gridyenileme()  //datagridimizi refresh etmek için method
        {
            String cmd = "SELECT * FROM tblUye ";
            csdgw2.loadDataGrid(dataGridView1, cmd);


        }
        private void AdminForm_Load(object sender, EventArgs e)
        {
            pictureBox11.Visible = false;
            pictureBox12.Visible = false;
            pictureBox13.Visible = false;
            pictureBox14.Visible = false;
            pictureBox15.Visible = false;
            pictureBox16.Visible = false;
            pictureBox17.Visible = false;
            pictureBox18.Visible = false;
            pictureBox19.Visible = false;
            pictureBox20.Visible = false;

            listBox2.AllowDrop = false;
            listBox3.AllowDrop = false;
            listBox4.AllowDrop = false;
            listBox5.AllowDrop = false;
            listBox6.AllowDrop = false;
            listBox7.AllowDrop = false;
            listBox8.AllowDrop = false;
            listBox9.AllowDrop = false;
            listBox10.AllowDrop = false;

            cb1.Items.Add(cb1.Text);
            cfcb.comboboxdoldurucu(cb1, "tblLokomotif", 1);

            dataGridView1.AllowUserToAddRows = false;
            dataGridView1.BackgroundColor = this.BackColor;
            gridyenileme();
        }

        private void groupBox5_Enter(object sender, EventArgs e)
        {

        }

        private void dataGridView1_SelectionChanged(object sender, EventArgs e)
        {
           

        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
          
        }

        private void listBox1_DragEnter(object sender, DragEventArgs e)
        {
            if (e.Data.GetDataPresent(typeof(DataGridViewSelectedRowCollection)))
            {
                e.Effect = DragDropEffects.Move;
            }
        }
        private void listBox1_DragDrop(object sender, DragEventArgs e)
        {
            DataGridViewSelectedRowCollection rows = (DataGridViewSelectedRowCollection)e.Data.GetData(typeof(DataGridViewSelectedRowCollection));

            foreach (DataGridViewRow row in rows)
            {
                listBox1.Items.Add(row.Cells[10].Value);
                
                //dataGridView1.Rows.Remove(row); griddeki veriyi silmeyelim   
            }
            
            double toplam = 0;
            //double renk;
            double[] topla = new double[listBox1.Items.Count]; 
            for (int i = 0; i < listBox1.Items.Count; i++) 
            {
                topla[i] = Convert.ToDouble(listBox1.Items[i].ToString());
                toplam = toplam + topla[i];
            }
           tk1 = toplam;
           txt1.Text = tk1.ToString();
           //y1.Text = "%" + tk1.ToString();
           vagonSayisi = 1;

           try
           {
               if (tk1 >= 1000)
               {
                   MessageBox.Show("Vagon sayisi yeterli değildir.Hizmetimiz maximum 1000 kolidir!");
                   return;

               }
               try
               {


                   if (tk1 >= 100)
                   {
                       txt1.Text = vagon1.ToString();
                   }
                   if (tk1 - 100 < 100 && tk1 > 100)
                   {
                       listBox1.AllowDrop = false;
                       listBox2.AllowDrop = true;
                       txt1.Text = vagon1.ToString();
                       listBox2.Items.Add(tk1 - 100);
                       txt2.Text = (tk1 - 100).ToString();
                       vagonSayisi = 2;
                       pictureBox11.Visible = true;
                       pictureBox1.Visible = false;
                   }
                   if (tk1 - 200 < 100 && tk1 > 200)
                   {
                       listBox1.AllowDrop = false;
                       listBox2.AllowDrop = false;
                       listBox3.AllowDrop = true;
                       listBox3.Items.Add(tk1 - 200);
                       txt3.Text = (tk1 - 200).ToString();
                       txt2.Text = vagon2.ToString();
                       vagonSayisi = 3;
                       pictureBox11.Visible = true;
                       pictureBox1.Visible = false;
                       pictureBox12.Visible = true;
                       pictureBox2.Visible = false;


                   }
                   if (tk1 - 300 < 100 && tk1 > 300)
                   {
                       listBox1.AllowDrop = false;
                       listBox2.AllowDrop = false;
                       listBox3.AllowDrop = false;
                       listBox4.AllowDrop = true;
                       listBox4.Items.Add(tk1 - 300);
                       txt4.Text = (tk1 - 300).ToString();
                       txt2.Text = vagon2.ToString();
                       txt3.Text = vagon3.ToString();
                       vagonSayisi = 4;
                       pictureBox11.Visible = true;
                       pictureBox1.Visible = false;
                       pictureBox12.Visible = true;
                       pictureBox2.Visible = false;
                       pictureBox13.Visible = true;
                       pictureBox3.Visible = false;


                   }
                   if (tk1 - 400 < 100 && tk1 > 400)
                   {
                       listBox1.AllowDrop = false;
                       listBox2.AllowDrop = false;
                       listBox3.AllowDrop = false;
                       listBox4.AllowDrop = false;
                       listBox5.AllowDrop = true;
                       listBox5.Items.Add(tk1 - 400);
                       txt5.Text = (tk1 - 400).ToString();
                       txt2.Text = vagon2.ToString();
                       txt3.Text = vagon3.ToString();
                       txt4.Text = vagon4.ToString();
                       vagonSayisi = 5;
                       pictureBox11.Visible = true;
                       pictureBox1.Visible = false;
                       pictureBox12.Visible = true;
                       pictureBox2.Visible = false;
                       pictureBox13.Visible = true;
                       pictureBox3.Visible = false;
                       pictureBox14.Visible = true;
                       pictureBox4.Visible = false;

                   }
                   if (tk1 - 500 < 100 && tk1 > 500)
                   {
                       listBox1.AllowDrop = false;
                       listBox2.AllowDrop = false;
                       listBox3.AllowDrop = false;
                       listBox4.AllowDrop = false;
                       listBox5.AllowDrop = false;
                       listBox6.AllowDrop = true;
                       listBox6.Items.Add(tk1 - 500);
                       txt6.Text = (tk1 - 500).ToString();
                       txt2.Text = vagon2.ToString();
                       txt3.Text = vagon3.ToString();
                       txt4.Text = vagon4.ToString();
                       txt5.Text = vagon5.ToString();
                       vagonSayisi = 6;
                       pictureBox11.Visible = true;
                       pictureBox1.Visible = false;
                       pictureBox12.Visible = true;
                       pictureBox2.Visible = false;
                       pictureBox13.Visible = true;
                       pictureBox3.Visible = false;
                       pictureBox14.Visible = true;
                       pictureBox4.Visible = false;
                       pictureBox15.Visible = true;
                       pictureBox5.Visible = false;


                   }
                   if (tk1 - 600 < 100 && tk1 > 600)
                   {
                       listBox1.AllowDrop = false;
                       listBox2.AllowDrop = false;
                       listBox3.AllowDrop = false;
                       listBox4.AllowDrop = false;
                       listBox5.AllowDrop = false;
                       listBox6.AllowDrop = false;
                       listBox7.AllowDrop = true;
                       listBox7.Items.Add(tk1 - 600);
                       txt7.Text = (tk1 - 600).ToString();
                       txt2.Text = vagon2.ToString();
                       txt3.Text = vagon3.ToString();
                       vagonSayisi = 7;
                       txt4.Text = vagon4.ToString();
                       txt5.Text = vagon5.ToString();
                       txt6.Text = vagon6.ToString();
                       pictureBox11.Visible = true;
                       pictureBox1.Visible = false;
                       pictureBox12.Visible = true;
                       pictureBox2.Visible = false;
                       pictureBox13.Visible = true;
                       pictureBox3.Visible = false;
                       pictureBox14.Visible = true;
                       pictureBox4.Visible = false;
                       pictureBox15.Visible = true;
                       pictureBox5.Visible = false;
                       pictureBox16.Visible = true;
                       pictureBox6.Visible = false;

                   }
                   if (tk1 - 700 < 100 && tk1 > 700)
                   {
                       listBox1.AllowDrop = false;
                       listBox2.AllowDrop = false;
                       listBox3.AllowDrop = false;
                       listBox4.AllowDrop = false;
                       listBox5.AllowDrop = false;
                       listBox6.AllowDrop = false;
                       listBox7.AllowDrop = false;
                       listBox8.AllowDrop = true;
                       listBox8.Items.Add(tk1 - 700);
                       txt8.Text = (tk1 - 700).ToString();
                       txt2.Text = vagon2.ToString();
                       txt3.Text = vagon3.ToString();
                       txt4.Text = vagon4.ToString();
                       txt5.Text = vagon5.ToString();
                       txt6.Text = vagon6.ToString();
                       txt7.Text = vagon7.ToString();
                       vagonSayisi = 8;
                       pictureBox11.Visible = true;
                       pictureBox1.Visible = false;
                       pictureBox12.Visible = true;
                       pictureBox2.Visible = false;
                       pictureBox13.Visible = true;
                       pictureBox3.Visible = false;
                       pictureBox14.Visible = true;
                       pictureBox4.Visible = false;
                       pictureBox15.Visible = true;
                       pictureBox5.Visible = false;
                       pictureBox16.Visible = true;
                       pictureBox6.Visible = false;
                       pictureBox17.Visible = true;
                       pictureBox7.Visible = false;


                   }
                   if (tk1 - 800 < 100 && tk1 > 800)
                   {
                       listBox9.AllowDrop = true;
                       listBox1.AllowDrop = false;
                       listBox2.AllowDrop = false;
                       listBox3.AllowDrop = false;
                       listBox4.AllowDrop = false;
                       listBox5.AllowDrop = false;
                       listBox6.AllowDrop = false;
                       listBox7.AllowDrop = false;
                       listBox8.AllowDrop = false;
                       listBox9.AllowDrop = true;
                       listBox9.Items.Add(tk1 - 800);
                       txt9.Text = (tk1 - 800).ToString();
                       txt2.Text = vagon2.ToString();
                       txt3.Text = vagon3.ToString();
                       txt4.Text = vagon4.ToString();
                       txt5.Text = vagon5.ToString();
                       txt6.Text = vagon6.ToString();
                       txt7.Text = vagon7.ToString();
                       txt8.Text = vagon8.ToString();
                       vagonSayisi = 9;
                       pictureBox11.Visible = true;
                       pictureBox1.Visible = false;
                       pictureBox12.Visible = true;
                       pictureBox2.Visible = false;
                       pictureBox13.Visible = true;
                       pictureBox3.Visible = false;
                       pictureBox14.Visible = true;
                       pictureBox4.Visible = false;
                       pictureBox15.Visible = true;
                       pictureBox5.Visible = false;
                       pictureBox16.Visible = true;
                       pictureBox6.Visible = false;
                       pictureBox17.Visible = true;
                       pictureBox7.Visible = false;
                       pictureBox18.Visible = true;
                       pictureBox8.Visible = false;


                   }
                   if (tk1 - 900 < 100 && tk1 > 900)
                   {
                       listBox1.AllowDrop = false;
                       listBox2.AllowDrop = false;
                       listBox3.AllowDrop = false;
                       listBox4.AllowDrop = false;
                       listBox5.AllowDrop = false;
                       listBox6.AllowDrop = false;
                       listBox7.AllowDrop = false;
                       listBox8.AllowDrop = false;
                       listBox9.AllowDrop = false;
                       listBox10.AllowDrop = true;
                       listBox10.Items.Add(tk1 - 900);
                       txt10.Text = (tk1 - 900).ToString();
                       vagonSayisi = 10;
                       txt2.Text = vagon2.ToString();
                       txt3.Text = vagon3.ToString();
                       txt4.Text = vagon4.ToString();
                       txt5.Text = vagon5.ToString();
                       txt6.Text = vagon6.ToString();
                       txt7.Text = vagon7.ToString();
                       txt8.Text = vagon8.ToString();
                       txt9.Text = vagon9.ToString();
                       pictureBox11.Visible = true;
                       pictureBox1.Visible = false;
                       pictureBox12.Visible = true;
                       pictureBox2.Visible = false;
                       pictureBox13.Visible = true;
                       pictureBox3.Visible = false;
                       pictureBox14.Visible = true;
                       pictureBox4.Visible = false;
                       pictureBox15.Visible = true;
                       pictureBox5.Visible = false;
                       pictureBox16.Visible = true;
                       pictureBox6.Visible = false;
                       pictureBox17.Visible = true;
                       pictureBox7.Visible = false;
                       pictureBox18.Visible = true;
                       pictureBox8.Visible = false;
                       pictureBox19.Visible = true;
                       pictureBox9.Visible = false;

                   }
                   if (tk1 - 1000 > 100)
                   {
                       MessageBox.Show("Vagon Sayisi Yeterli değil.Ek lokomotif tahsis ediniz!");
                       listBox1.Items.Clear();


                   }


               }


               catch (Exception)
               {

                   MessageBox.Show("1.trayda hata var");
               }

           }
           catch (Exception)
           {

               MessageBox.Show("Hata olustu");
           }
            
          
         
        }
        private void dataGridView1_MouseDown(object sender, MouseEventArgs e)
        {
            dataGridView1.DoDragDrop(dataGridView1.SelectedRows, DragDropEffects.Move);
        }

        private void listBox2_DragEnter(object sender, DragEventArgs e)
        {
            if (e.Data.GetDataPresent(typeof(DataGridViewSelectedRowCollection)))
            {
                e.Effect = DragDropEffects.Move;
            }
        }

        private void listBox3_DragEnter(object sender, DragEventArgs e)
        {
            if (e.Data.GetDataPresent(typeof(DataGridViewSelectedRowCollection)))
            {
                e.Effect = DragDropEffects.Move;
            }
        }

        private void listBox4_DragEnter(object sender, DragEventArgs e)
        {
            if (e.Data.GetDataPresent(typeof(DataGridViewSelectedRowCollection)))
            {
                e.Effect = DragDropEffects.Move;
            }
        }

        private void listBox5_DragEnter(object sender, DragEventArgs e)
        {
            if (e.Data.GetDataPresent(typeof(DataGridViewSelectedRowCollection)))
            {
                e.Effect = DragDropEffects.Move;
            }
        }

        private void listBox6_DragEnter(object sender, DragEventArgs e)
        {
            if (e.Data.GetDataPresent(typeof(DataGridViewSelectedRowCollection)))
            {
                e.Effect = DragDropEffects.Move;
            }
        }

        private void listBox7_DragEnter(object sender, DragEventArgs e)
        {
            if (e.Data.GetDataPresent(typeof(DataGridViewSelectedRowCollection)))
            {
                e.Effect = DragDropEffects.Move;
            }
        }

        private void listBox8_DragEnter(object sender, DragEventArgs e)
        {
            if (e.Data.GetDataPresent(typeof(DataGridViewSelectedRowCollection)))
            {
                e.Effect = DragDropEffects.Move;
            }
        }

        private void listBox9_DragEnter(object sender, DragEventArgs e)
        {
            if (e.Data.GetDataPresent(typeof(DataGridViewSelectedRowCollection)))
            {
                e.Effect = DragDropEffects.Move;
            }
        }

        private void listBox10_DragEnter(object sender, DragEventArgs e)
        {
            if (e.Data.GetDataPresent(typeof(DataGridViewSelectedRowCollection)))
            {
                e.Effect = DragDropEffects.Move;
            }
        }

        private void listBox2_DragDrop(object sender, DragEventArgs e)
        {
            DataGridViewSelectedRowCollection rows = (DataGridViewSelectedRowCollection)e.Data.GetData(typeof(DataGridViewSelectedRowCollection));

            foreach (DataGridViewRow row in rows)
            {
                listBox2.Items.Add(row.Cells[10].Value);
                //dataGridView1.Rows.Remove(row); griddeki veriyi silmeyelim   
            }

            double toplam = 0;
            //double renk;
            double[] topla = new double[listBox2.Items.Count];
            for (int i = 0; i < listBox2.Items.Count; i++)
            {
                topla[i] = Convert.ToDouble(listBox2.Items[i].ToString());
                toplam = toplam + topla[i];
            }
            tk1 = toplam;

            txt2.Text = tk1.ToString();
            //y2.Text = "%" + tk1.ToString();

            try
            {
                if (tk1 >= 900)
                {
                    MessageBox.Show("Yeterli Vagon Yok");
                    return;
                }
                try
                {
                    if (tk1 >= 100)
                    {
                        txt2.Text = vagon2.ToString();
                    }

                    if (tk1 - 100 < 100 && tk1 > 100)
                    {
                        listBox2.AllowDrop = false;
                        listBox3.AllowDrop = true;
                        listBox3.Items.Add(tk1 - 100);
                        txt3.Text = (tk1 - 100).ToString();
                        txt2.Text = vagon2.ToString();
                        vagonSayisi = 3;
                        pictureBox12.Visible = true;
                        pictureBox2.Visible = false;

                    }
                    if (tk1 - 200 < 100 && tk1 > 200)
                    {
                        listBox2.AllowDrop = false;
                        listBox3.AllowDrop = false;
                        listBox4.AllowDrop = true;
                        listBox4.Items.Add(tk1 - 200);
                        txt4.Text = (tk1 - 200).ToString();
                        txt2.Text = vagon2.ToString();
                        txt3.Text = vagon3.ToString();
                        vagonSayisi = 4;
                        pictureBox12.Visible = true;
                        pictureBox2.Visible = false;
                        pictureBox13.Visible = true;
                        pictureBox3.Visible = false;


                    }
                    if (tk1 - 300 < 100 && tk1 > 300)
                    {
                        listBox2.AllowDrop = false;
                        listBox3.AllowDrop = false;
                        listBox4.AllowDrop = false;
                        listBox5.AllowDrop = true;
                        listBox5.Items.Add(tk1 - 300);
                        txt5.Text = (tk1 - 300).ToString();
                        txt2.Text = vagon2.ToString();
                        txt3.Text = vagon3.ToString();
                        vagonSayisi = 5;

                        txt4.Text = vagon4.ToString();
                        pictureBox12.Visible = true;
                        pictureBox2.Visible = false;
                        pictureBox13.Visible = true;
                        pictureBox3.Visible = false;
                        pictureBox14.Visible = true;
                        pictureBox4.Visible = false;

                    }
                    if (tk1 - 400 < 100 && tk1 > 400)
                    {
                        listBox2.AllowDrop = false;
                        listBox3.AllowDrop = false;
                        listBox4.AllowDrop = false;
                        listBox5.AllowDrop = false;
                        listBox6.AllowDrop = true;
                        listBox6.Items.Add(tk1 - 400);
                        txt6.Text = (tk1 - 400).ToString();
                        txt2.Text = vagon2.ToString();
                        txt3.Text = vagon3.ToString();
                        vagonSayisi = 6;
                        txt4.Text = vagon4.ToString();
                        txt5.Text = vagon5.ToString();
                        pictureBox12.Visible = true;
                        pictureBox2.Visible = false;
                        pictureBox13.Visible = true;
                        pictureBox3.Visible = false;
                        pictureBox14.Visible = true;
                        pictureBox4.Visible = false;
                        pictureBox15.Visible = true;
                        pictureBox5.Visible = false;


                    }
                    if (tk1 - 500 < 100 && tk1 > 500)
                    {
                        listBox2.AllowDrop = false;
                        listBox3.AllowDrop = false;
                        listBox4.AllowDrop = false;
                        listBox5.AllowDrop = false;
                        listBox6.AllowDrop = false;
                        listBox7.AllowDrop = true;
                        listBox7.Items.Add(tk1 - 500);
                        txt7.Text = (tk1 - 500).ToString();
                        txt2.Text = vagon2.ToString();
                        txt3.Text = vagon3.ToString();
                        vagonSayisi = 7;
                        txt4.Text = vagon4.ToString();
                        txt5.Text = vagon5.ToString();
                        txt6.Text = vagon6.ToString();
                        pictureBox12.Visible = true;
                        pictureBox2.Visible = false;
                        pictureBox13.Visible = true;
                        pictureBox3.Visible = false;
                        pictureBox14.Visible = true;
                        pictureBox4.Visible = false;
                        pictureBox15.Visible = true;
                        pictureBox5.Visible = false;
                        pictureBox16.Visible = true;
                        pictureBox6.Visible = false;



                    }
                    if (tk1 - 600 < 100 && tk1 > 600)
                    {
                        listBox2.AllowDrop = false;
                        listBox3.AllowDrop = false;
                        listBox4.AllowDrop = false;
                        listBox5.AllowDrop = false;
                        listBox6.AllowDrop = false;
                        listBox7.AllowDrop = false;
                        listBox8.AllowDrop = true;
                        listBox8.Items.Add(tk1 - 600);
                        txt8.Text = (tk1 - 600).ToString();
                        txt2.Text = vagon2.ToString();
                        txt3.Text = vagon3.ToString();
                        txt4.Text = vagon4.ToString();
                        txt5.Text = vagon5.ToString();
                        txt6.Text = vagon6.ToString();
                        txt7.Text = vagon7.ToString();
                        vagonSayisi = 8;
                        pictureBox12.Visible = true;
                        pictureBox2.Visible = false;
                        pictureBox13.Visible = true;
                        pictureBox3.Visible = false;
                        pictureBox14.Visible = true;
                        pictureBox4.Visible = false;
                        pictureBox15.Visible = true;
                        pictureBox5.Visible = false;
                        pictureBox16.Visible = true;
                        pictureBox6.Visible = false;
                        pictureBox17.Visible = true;
                        pictureBox7.Visible = false;

                    }
                    if (tk1 - 700 < 100 && tk1 > 700)
                    {
                        listBox9.Items.Add(tk1 - 700);
                        txt9.Text = (tk1 - 700).ToString();
                        listBox2.AllowDrop = false;
                        listBox3.AllowDrop = false;
                        listBox4.AllowDrop = false;
                        listBox5.AllowDrop = false;
                        listBox6.AllowDrop = false;
                        listBox7.AllowDrop = false;
                        listBox8.AllowDrop = false;
                        listBox9.AllowDrop = true;
                        txt2.Text = vagon2.ToString();
                        txt3.Text = vagon3.ToString();
                        txt4.Text = vagon4.ToString();
                        txt5.Text = vagon5.ToString();
                        txt6.Text = vagon6.ToString();
                        txt7.Text = vagon7.ToString();
                        txt8.Text = vagon8.ToString();
                        vagonSayisi = 9;
                        pictureBox12.Visible = true;
                        pictureBox2.Visible = false;
                        pictureBox13.Visible = true;
                        pictureBox3.Visible = false;
                        pictureBox14.Visible = true;
                        pictureBox4.Visible = false;
                        pictureBox15.Visible = true;
                        pictureBox5.Visible = false;
                        pictureBox16.Visible = true;
                        pictureBox6.Visible = false;
                        pictureBox17.Visible = true;
                        pictureBox7.Visible = false;
                        pictureBox18.Visible = true;
                        pictureBox8.Visible = false;
                    }
                    if (tk1 - 800 < 100 && tk1 > 800)
                    {
                        listBox10.Items.Add(tk1 - 800);
                        txt10.Text = (tk1 - 800).ToString();
                        listBox2.AllowDrop = false;
                        listBox3.AllowDrop = false;
                        listBox4.AllowDrop = false;
                        listBox5.AllowDrop = false;
                        listBox6.AllowDrop = false;
                        listBox7.AllowDrop = false;
                        listBox8.AllowDrop = false;
                        listBox9.AllowDrop = false;
                        listBox10.AllowDrop = true;
                        txt2.Text = vagon2.ToString();
                        txt3.Text = vagon3.ToString();
                        txt4.Text = vagon4.ToString();
                        txt5.Text = vagon5.ToString();
                        txt6.Text = vagon6.ToString();
                        txt7.Text = vagon7.ToString();
                        txt8.Text = vagon8.ToString();
                        txt9.Text = vagon9.ToString();
                        vagonSayisi = 10;
                        pictureBox12.Visible = true;
                        pictureBox2.Visible = false;
                        pictureBox13.Visible = true;
                        pictureBox3.Visible = false;
                        pictureBox14.Visible = true;
                        pictureBox4.Visible = false;
                        pictureBox15.Visible = true;
                        pictureBox5.Visible = false;
                        pictureBox16.Visible = true;
                        pictureBox6.Visible = false;
                        pictureBox17.Visible = true;
                        pictureBox7.Visible = false;
                        pictureBox18.Visible = true;
                        pictureBox8.Visible = false;
                        pictureBox19.Visible = true;
                        pictureBox9.Visible = false;
                    }

                }
                catch (Exception)
                {

                    MessageBox.Show("1.trayda hata var");
                }
            }
            catch (Exception)
            {

                MessageBox.Show("Bir hata olustu");
            }
            
            
          
        }

        private void listBox3_DragDrop(object sender, DragEventArgs e)
        {
            DataGridViewSelectedRowCollection rows = (DataGridViewSelectedRowCollection)e.Data.GetData(typeof(DataGridViewSelectedRowCollection));

            foreach (DataGridViewRow row in rows)
            {
                listBox3.Items.Add(row.Cells[10].Value);
                //dataGridView1.Rows.Remove(row); griddeki veriyi silmeyelim   
            }
            double toplam = 0;
            //double renk;
            double[] topla = new double[listBox3.Items.Count];
            for (int i = 0; i < listBox3.Items.Count; i++)
            {
                topla[i] = Convert.ToDouble(listBox3.Items[i].ToString());
                toplam = toplam + topla[i];
            }
            tk1 = toplam;
            txt3.Text = tk1.ToString();
            // y3.Text = "%" + tk1.ToString();
            try
            {
                if (tk1 >= 800)
                {
                    MessageBox.Show("Yeterli Vagon Yok");
                    return;
                }
                try
                {
                    if (tk1 >= 100)
                    {

                        txt3.Text = vagon3.ToString();
                    }

                    if (tk1 - 100 < 100 && tk1 > 100)
                    {
                        listBox3.AllowDrop = false;
                        listBox4.AllowDrop = true;
                        listBox4.Items.Add(tk1 - 100);
                        txt4.Text = (tk1 - 100).ToString();
                        txt3.Text = vagon3.ToString();
                        vagonSayisi = 4;
                        pictureBox13.Visible = true;
                        pictureBox3.Visible = false;
                    }
                    if (tk1 - 200 < 100 && tk1 > 200)
                    {
                        listBox3.AllowDrop = false;
                        listBox4.AllowDrop = false;
                        listBox5.AllowDrop = true;
                        listBox5.Items.Add(tk1 - 200);
                        txt5.Text = (tk1 - 200).ToString();
                        txt3.Text = vagon3.ToString();
                        txt4.Text = vagon4.ToString();
                        vagonSayisi = 5;
                        pictureBox13.Visible = true;
                        pictureBox3.Visible = false;
                        pictureBox14.Visible = true;
                        pictureBox4.Visible = false;
                    }
                    if (tk1 - 300 < 100 && tk1 > 300)
                    {
                        listBox3.AllowDrop = false;
                        listBox4.AllowDrop = false;
                        listBox5.AllowDrop = false;
                        listBox6.AllowDrop = true;
                        listBox6.Items.Add(tk1 - 300);
                        txt6.Text = (tk1 - 300).ToString();
                        vagonSayisi = 6;
                        txt3.Text = vagon3.ToString();
                        txt4.Text = vagon4.ToString();
                        txt5.Text = vagon5.ToString();
                        pictureBox13.Visible = true;
                        pictureBox3.Visible = false;
                        pictureBox14.Visible = true;
                        pictureBox4.Visible = false;
                        pictureBox15.Visible = true;
                        pictureBox5.Visible = false;

                    }
                    if (tk1 - 400 < 100 && tk1 > 400)
                    {
                        listBox3.AllowDrop = false;
                        listBox4.AllowDrop = false;
                        listBox5.AllowDrop = false;
                        listBox6.AllowDrop = false;
                        listBox7.AllowDrop = true;
                        listBox7.Items.Add(tk1 - 400);
                        txt7.Text = (tk1 - 400).ToString();
                        txt3.Text = vagon3.ToString();
                        txt4.Text = vagon4.ToString();
                        txt5.Text = vagon5.ToString();
                        txt6.Text = vagon6.ToString();
                        vagonSayisi = 7;
                        pictureBox13.Visible = true;
                        pictureBox3.Visible = false;
                        pictureBox14.Visible = true;
                        pictureBox4.Visible = false;
                        pictureBox15.Visible = true;
                        pictureBox5.Visible = false;
                        pictureBox16.Visible = true;
                        pictureBox6.Visible = false;

                    }
                    if (tk1 - 500 < 100 && tk1 > 500)
                    {
                        listBox3.AllowDrop = false;
                        listBox4.AllowDrop = false;
                        listBox5.AllowDrop = false;
                        listBox6.AllowDrop = false;
                        listBox7.AllowDrop = false;
                        listBox8.AllowDrop = true;
                        listBox8.Items.Add(tk1 - 500);
                        txt8.Text = (tk1 - 500).ToString();
                        txt3.Text = vagon3.ToString();
                        txt4.Text = vagon4.ToString();
                        txt5.Text = vagon5.ToString();
                        txt6.Text = vagon6.ToString();
                        txt7.Text = vagon7.ToString();
                        vagonSayisi = 8;
                        pictureBox13.Visible = true;
                        pictureBox3.Visible = false;
                        pictureBox14.Visible = true;
                        pictureBox4.Visible = false;
                        pictureBox15.Visible = true;
                        pictureBox5.Visible = false;
                        pictureBox16.Visible = true;
                        pictureBox6.Visible = false;
                        pictureBox17.Visible = true;
                        pictureBox7.Visible = false;

                    }
                    if (tk1 - 600 < 100 && tk1 > 600)
                    {
                        listBox3.AllowDrop = false;
                        listBox4.AllowDrop = false;
                        listBox5.AllowDrop = false;
                        listBox6.AllowDrop = false;
                        listBox7.AllowDrop = false;
                        listBox8.AllowDrop = false;
                        listBox9.AllowDrop = true;
                        listBox9.Items.Add(tk1 - 600);
                        txt9.Text = (tk1 - 600).ToString();
                        vagonSayisi = 9;
                        txt3.Text = vagon3.ToString();
                        txt4.Text = vagon4.ToString();
                        txt5.Text = vagon5.ToString();
                        txt6.Text = vagon6.ToString();
                        txt7.Text = vagon7.ToString();
                        txt8.Text = vagon8.ToString();
                        pictureBox13.Visible = true;
                        pictureBox3.Visible = false;
                        pictureBox14.Visible = true;
                        pictureBox4.Visible = false;
                        pictureBox15.Visible = true;
                        pictureBox5.Visible = false;
                        pictureBox16.Visible = true;
                        pictureBox6.Visible = false;
                        pictureBox17.Visible = true;
                        pictureBox7.Visible = false;
                        pictureBox18.Visible = true;
                        pictureBox8.Visible = false;

                    }
                    if (tk1 - 700 < 100 && tk1 > 700)
                    {
                        listBox3.AllowDrop = false;
                        listBox4.AllowDrop = false;
                        listBox5.AllowDrop = false;
                        listBox6.AllowDrop = false;
                        listBox7.AllowDrop = false;
                        listBox8.AllowDrop = false;
                        listBox9.AllowDrop = false;
                        listBox10.AllowDrop = true;
                        listBox10.Items.Add(tk1 - 700);
                        txt10.Text = (tk1 - 700).ToString();
                        vagonSayisi = 10;
                        txt2.Text = vagon2.ToString();
                        txt3.Text = vagon3.ToString();
                        txt4.Text = vagon4.ToString();
                        txt5.Text = vagon5.ToString();
                        txt6.Text = vagon6.ToString();
                        txt7.Text = vagon7.ToString();
                        txt8.Text = vagon8.ToString();
                        txt9.Text = vagon9.ToString();
                        pictureBox13.Visible = true;
                        pictureBox3.Visible = false;
                        pictureBox14.Visible = true;
                        pictureBox4.Visible = false;
                        pictureBox15.Visible = true;
                        pictureBox5.Visible = false;
                        pictureBox16.Visible = true;
                        pictureBox6.Visible = false;
                        pictureBox17.Visible = true;
                        pictureBox7.Visible = false;
                        pictureBox18.Visible = true;
                        pictureBox8.Visible = false;
                        pictureBox19.Visible = true;
                        pictureBox9.Visible = false;
                    }



                }
                catch (Exception)
                {

                    MessageBox.Show("1.trayda hata var");
                }
            }
            catch (Exception)
            {

                MessageBox.Show("Bir hata olustu");
            }


          
        }

        private void listBox4_DragDrop(object sender, DragEventArgs e)
        {
            DataGridViewSelectedRowCollection rows = (DataGridViewSelectedRowCollection)e.Data.GetData(typeof(DataGridViewSelectedRowCollection));

            foreach (DataGridViewRow row in rows)
            {
                listBox4.Items.Add(row.Cells[10].Value);
                //dataGridView1.Rows.Remove(row); griddeki veriyi silmeyelim   
            }
            double toplam = 0;
            //double renk;
            double[] topla = new double[listBox4.Items.Count];
            for (int i = 0; i < listBox4.Items.Count; i++)
            {
                topla[i] = Convert.ToDouble(listBox4.Items[i].ToString());
                toplam = toplam + topla[i];
            }
            tk1 = toplam;
            txt4.Text = tk1.ToString();
           // y4.Text = "%" + tk1.ToString();
            try
            {
                if (tk1 >= 700)
                {
                    MessageBox.Show("Yeterli Vagon Yok");
                    return;
                }
                try
                {
                    if (tk1 >= 100)
                    {

                        txt4.Text = vagon4.ToString();
                    }

                    if (tk1 - 100 < 100 && tk1 > 100)
                    {
                        listBox4.AllowDrop = false;
                        listBox5.AllowDrop = true;
                        listBox5.Items.Add(tk1 - 100);
                        vagonSayisi = 5;
                        txt5.Text = (tk1 - 100).ToString();
                        txt4.Text = vagon4.ToString();
                        pictureBox14.Visible = true;
                        pictureBox4.Visible = false;

                    }
                    if (tk1 - 200 < 100 && tk1 > 200)
                    {

                        listBox4.AllowDrop = false;
                        listBox5.AllowDrop = false;
                        listBox6.AllowDrop = true;
                        listBox6.Items.Add(tk1 - 200);
                        vagonSayisi = 6;
                        txt6.Text = (tk1 - 200).ToString();
                        txt4.Text = vagon4.ToString();
                        txt5.Text = vagon5.ToString();
                        pictureBox14.Visible = true;
                        pictureBox4.Visible = false;
                        pictureBox15.Visible = true;
                        pictureBox5.Visible = false;
                    }
                    if (tk1 - 300 < 100 && tk1 > 300)
                    {
                        listBox4.AllowDrop = false;
                        listBox5.AllowDrop = false;
                        listBox6.AllowDrop = false;
                        listBox7.AllowDrop = true;
                        listBox7.Items.Add(tk1 - 300);
                        txt7.Text = (tk1 - 300).ToString();
                        txt4.Text = vagon4.ToString();
                        txt5.Text = vagon5.ToString();
                        txt6.Text = vagon6.ToString();
                        vagonSayisi = 7;
                        pictureBox14.Visible = true;
                        pictureBox4.Visible = false;
                        pictureBox15.Visible = true;
                        pictureBox5.Visible = false;
                        pictureBox16.Visible = true;
                        pictureBox6.Visible = false;

                    }
                    if (tk1 - 400 < 100 && tk1 > 400)
                    {
                        listBox4.AllowDrop = false;
                        listBox5.AllowDrop = false;
                        listBox6.AllowDrop = false;
                        listBox7.AllowDrop = false;
                        listBox8.AllowDrop = true;
                        listBox8.Items.Add(tk1 - 400);
                        txt8.Text = (tk1 - 400).ToString();
                        vagonSayisi = 8;
                        txt4.Text = vagon4.ToString();
                        txt5.Text = vagon5.ToString();
                        txt6.Text = vagon6.ToString();
                        txt7.Text = vagon7.ToString();
                        pictureBox14.Visible = true;
                        pictureBox4.Visible = false;
                        pictureBox15.Visible = true;
                        pictureBox5.Visible = false;
                        pictureBox16.Visible = true;
                        pictureBox6.Visible = false;
                        pictureBox17.Visible = true;
                        pictureBox7.Visible = false;


                    }
                    if (tk1 - 500 < 100 && tk1 > 500)
                    {
                        listBox4.AllowDrop = false;
                        listBox5.AllowDrop = false;
                        listBox6.AllowDrop = false;
                        listBox7.AllowDrop = false;
                        listBox8.AllowDrop = false;
                        listBox9.AllowDrop = true;
                        listBox9.Items.Add(tk1 - 500);
                        vagonSayisi = 9;
                        txt9.Text = (tk1 - 500).ToString();
                        txt4.Text = vagon4.ToString();
                        txt5.Text = vagon5.ToString();
                        txt6.Text = vagon6.ToString();
                        txt7.Text = vagon7.ToString();
                        txt8.Text = vagon8.ToString();
                        pictureBox14.Visible = true;
                        pictureBox4.Visible = false;
                        pictureBox15.Visible = true;
                        pictureBox5.Visible = false;
                        pictureBox16.Visible = true;
                        pictureBox6.Visible = false;
                        pictureBox17.Visible = true;
                        pictureBox7.Visible = false;
                        pictureBox18.Visible = true;
                        pictureBox8.Visible = false;

                    }
                    if (tk1 - 600 < 100 && tk1 > 600)
                    {
                        listBox4.AllowDrop = false;
                        listBox5.AllowDrop = false;
                        listBox6.AllowDrop = false;
                        listBox7.AllowDrop = false;
                        listBox8.AllowDrop = false;
                        listBox9.AllowDrop = false;
                        listBox10.AllowDrop = true;
                        listBox10.Items.Add(tk1 - 600);
                        vagonSayisi = 10;
                        txt10.Text = (tk1 - 600).ToString();
                        txt4.Text = vagon4.ToString();
                        txt5.Text = vagon5.ToString();
                        txt6.Text = vagon6.ToString();
                        txt7.Text = vagon7.ToString();
                        txt8.Text = vagon8.ToString();
                        txt9.Text = vagon9.ToString();
                        pictureBox14.Visible = true;
                        pictureBox4.Visible = false;
                        pictureBox15.Visible = true;
                        pictureBox5.Visible = false;
                        pictureBox16.Visible = true;
                        pictureBox6.Visible = false;
                        pictureBox17.Visible = true;
                        pictureBox7.Visible = false;
                        pictureBox18.Visible = true;
                        pictureBox8.Visible = false;
                        pictureBox19.Visible = true;
                        pictureBox9.Visible = false;

                    }


                }
                catch (Exception)
                {

                    MessageBox.Show("1.trayda hata var");
                }
            }
            catch (Exception)
            {

                MessageBox.Show("Bir hata olustu");
            }

           
        }

        private void listBox5_DragDrop(object sender, DragEventArgs e)
        {
            DataGridViewSelectedRowCollection rows = (DataGridViewSelectedRowCollection)e.Data.GetData(typeof(DataGridViewSelectedRowCollection));

            foreach (DataGridViewRow row in rows)
            {
                listBox5.Items.Add(row.Cells[10].Value);
                //dataGridView1.Rows.Remove(row); griddeki veriyi silmeyelim   
            }
            double toplam = 0;
            //double renk;
            double[] topla = new double[listBox5.Items.Count];
            for (int i = 0; i < listBox5.Items.Count; i++)
            {
                topla[i] = Convert.ToDouble(listBox5.Items[i].ToString());
                toplam = toplam + topla[i];
            }
            tk1 = toplam;
            txt5.Text = tk1.ToString();
           // y5.Text = "%" + tk1.ToString();
            try
            {
                if (tk1 >= 600)
                {
                    MessageBox.Show("Yeterli Vagon Yok");
                    return;
                }
                try
                {
                    if (tk1 >= 100)
                    {

                        txt5.Text = vagon5.ToString();
                    }

                    if (tk1 - 100 < 100 && tk1 > 100)
                    {
                        listBox5.AllowDrop = false;
                        listBox6.AllowDrop = true;
                        listBox6.Items.Add(tk1 - 100);
                        vagonSayisi = 6;
                        txt6.Text = (tk1 - 100).ToString();
                        txt5.Text = vagon5.ToString();
                        pictureBox15.Visible = true;
                        pictureBox5.Visible = false;

                    }
                    if (tk1 - 200 < 100 && tk1 > 200)
                    {
                        listBox5.AllowDrop = false;
                        listBox6.AllowDrop = false;
                        listBox7.AllowDrop = true;
                        listBox7.Items.Add(tk1 - 200);
                        vagonSayisi = 7;
                        txt7.Text = (tk1 - 200).ToString();
                        txt5.Text = vagon5.ToString();
                        txt6.Text = vagon6.ToString();
                        pictureBox15.Visible = true;
                        pictureBox5.Visible = false;
                        pictureBox16.Visible = true;
                        pictureBox6.Visible = false;



                    }
                    if (tk1 - 300 < 100 && tk1 > 300)
                    {
                        listBox5.AllowDrop = false;
                        listBox6.AllowDrop = false;
                        listBox7.AllowDrop = false;
                        listBox8.AllowDrop = true;
                        listBox8.Items.Add(tk1 - 300);
                        vagonSayisi = 8;
                        txt8.Text = (tk1 - 300).ToString();

                        txt5.Text = vagon5.ToString();
                        txt6.Text = vagon6.ToString();
                        txt7.Text = vagon7.ToString();
                        pictureBox15.Visible = true;
                        pictureBox5.Visible = false;
                        pictureBox16.Visible = true;
                        pictureBox6.Visible = false;
                        pictureBox17.Visible = true;
                        pictureBox7.Visible = false;


                    }
                    if (tk1 - 400 < 100 && tk1 > 400)
                    {
                        listBox5.AllowDrop = false;
                        listBox6.AllowDrop = false;
                        listBox7.AllowDrop = false;
                        listBox8.AllowDrop = false;
                        listBox9.AllowDrop = true;
                        listBox9.Items.Add(tk1 - 400);
                        vagonSayisi = 9;
                        txt9.Text = (tk1 - 400).ToString();
                        txt5.Text = vagon5.ToString();
                        txt6.Text = vagon6.ToString();
                        txt7.Text = vagon7.ToString();
                        txt8.Text = vagon8.ToString();
                        pictureBox15.Visible = true;
                        pictureBox5.Visible = false;
                        pictureBox16.Visible = true;
                        pictureBox6.Visible = false;
                        pictureBox17.Visible = true;
                        pictureBox7.Visible = false;
                        pictureBox18.Visible = true;
                        pictureBox8.Visible = false;

                    }
                    if (tk1 - 500 < 100 && tk1 > 500)
                    {
                        listBox5.AllowDrop = false;
                        listBox6.AllowDrop = false;
                        listBox7.AllowDrop = false;
                        listBox8.AllowDrop = false;
                        listBox9.AllowDrop = false;
                        listBox10.AllowDrop = true;
                        listBox10.Items.Add(tk1 - 500);
                        vagonSayisi = 10;
                        txt10.Text = (tk1 - 500).ToString();
                        txt5.Text = vagon5.ToString();
                        txt6.Text = vagon6.ToString();
                        txt7.Text = vagon7.ToString();
                        txt8.Text = vagon8.ToString();
                        txt9.Text = vagon9.ToString();
                        pictureBox15.Visible = true;
                        pictureBox5.Visible = false;
                        pictureBox16.Visible = true;
                        pictureBox6.Visible = false;
                        pictureBox17.Visible = true;
                        pictureBox7.Visible = false;
                        pictureBox18.Visible = true;
                        pictureBox8.Visible = false;
                        pictureBox19.Visible = true;
                        pictureBox9.Visible = false;
                    }

                }
                catch (Exception)
                {

                    MessageBox.Show("1.trayda hata var");
                }
            }
            catch (Exception)
            {

                MessageBox.Show("Bir hata olustu");
            }


        
        }

        private void listBox6_DragDrop(object sender, DragEventArgs e)
        {
            DataGridViewSelectedRowCollection rows = (DataGridViewSelectedRowCollection)e.Data.GetData(typeof(DataGridViewSelectedRowCollection));

            foreach (DataGridViewRow row in rows)
            {
                listBox6.Items.Add(row.Cells[10].Value);
                //dataGridView1.Rows.Remove(row); griddeki veriyi silmeyelim   
            }
            double toplam = 0;
            //double renk;
            double[] topla = new double[listBox6.Items.Count];
            for (int i = 0; i < listBox6.Items.Count; i++)
            {
                topla[i] = Convert.ToDouble(listBox6.Items[i].ToString());
                toplam = toplam + topla[i];
            }
            tk1 = toplam;
            txt6.Text = tk1.ToString();
            //y6.Text = "%" + tk1.ToString();
            try
            {
                if (tk1 >= 500)
                {
                    MessageBox.Show("Yeterli Vagon Yok");
                    return;
                }
                try
                {
                    if (tk1 >= 100)
                    {

                        txt6.Text = vagon6.ToString();
                    }

                    if (tk1 - 100 < 100 && tk1 > 100)
                    {
                        listBox6.AllowDrop = false;
                        listBox7.AllowDrop = true;
                        listBox7.Items.Add(tk1 - 100);
                        vagonSayisi = 7;
                        txt6.Text = vagon6.ToString();
                        txt7.Text = (tk1 - 100).ToString();
                        pictureBox16.Visible = true;
                        pictureBox6.Visible = false;

                    }
                    if (tk1 - 200 < 100 && tk1 > 200)
                    {
                        listBox6.AllowDrop = false;
                        listBox7.AllowDrop = false;
                        listBox8.AllowDrop = true;
                        listBox8.Items.Add(tk1 - 200);
                        vagonSayisi = 8;
                        txt8.Text = (tk1 - 200).ToString();

                        txt6.Text = vagon6.ToString();
                        txt7.Text = vagon7.ToString();
                        pictureBox16.Visible = true;
                        pictureBox6.Visible = false;
                        pictureBox17.Visible = true;
                        pictureBox7.Visible = false;



                    }
                    if (tk1 - 300 < 100 && tk1 > 300)
                    {
                        listBox6.AllowDrop = false;
                        listBox7.AllowDrop = false;
                        listBox8.AllowDrop = false;
                        listBox9.AllowDrop = true;
                        listBox9.Items.Add(tk1 - 300);
                        vagonSayisi = 9;
                        txt9.Text = (tk1 - 300).ToString();
                        txt6.Text = vagon6.ToString();
                        txt7.Text = vagon7.ToString();
                        txt8.Text = vagon8.ToString();
                        pictureBox16.Visible = true;
                        pictureBox6.Visible = false;
                        pictureBox17.Visible = true;
                        pictureBox7.Visible = false;
                        pictureBox18.Visible = true;
                        pictureBox8.Visible = false;

                    }
                    if (tk1 - 400 < 100 && tk1 > 400)
                    {
                        listBox6.AllowDrop = false;
                        listBox7.AllowDrop = false;
                        listBox8.AllowDrop = false;
                        listBox9.AllowDrop = false;
                        listBox10.AllowDrop = true;
                        listBox10.Items.Add(tk1 - 400);
                        vagonSayisi = 10;
                        txt10.Text = (tk1 - 400).ToString();
                        txt6.Text = vagon6.ToString();
                        txt7.Text = vagon7.ToString();
                        txt8.Text = vagon8.ToString();
                        txt9.Text = vagon9.ToString();
                        pictureBox16.Visible = true;
                        pictureBox6.Visible = false;
                        pictureBox17.Visible = true;
                        pictureBox7.Visible = false;
                        pictureBox18.Visible = true;
                        pictureBox8.Visible = false;
                        pictureBox19.Visible = true;
                        pictureBox9.Visible = false;

                    }


                }
                catch (Exception)
                {

                    MessageBox.Show("1.trayda hata var");
                }
            }
            catch (Exception)
            {
                MessageBox.Show("Bir hata olustu");
            }


          
        }

        private void listBox7_DragDrop(object sender, DragEventArgs e)
        {
            DataGridViewSelectedRowCollection rows = (DataGridViewSelectedRowCollection)e.Data.GetData(typeof(DataGridViewSelectedRowCollection));

            foreach (DataGridViewRow row in rows)
            {
                listBox7.Items.Add(row.Cells[10].Value);
                //dataGridView1.Rows.Remove(row); griddeki veriyi silmeyelim   
            }
            double toplam = 0;
            //double renk;
            double[] topla = new double[listBox7.Items.Count];
            for (int i = 0; i < listBox7.Items.Count; i++)
            {
                topla[i] = Convert.ToDouble(listBox7.Items[i].ToString());
                toplam = toplam + topla[i];
            }
            tk1 = toplam;
            txt7.Text = tk1.ToString();
           // y7.Text = "%" + tk1.ToString();
            try
            {
                if (tk1 >= 400)
                {
                    MessageBox.Show("Yeterli Vagon Yok");
                    return;
                }
                try
                {
                    if (tk1 >= 100)
                    {

                        txt7.Text = vagon7.ToString();
                    }

                    if (tk1 - 100 < 100 && tk1 > 100)
                    {
                        listBox7.AllowDrop = false;
                        listBox8.AllowDrop = true;
                        listBox8.Items.Add(tk1 - 100);
                        vagonSayisi = 8;
                        txt8.Text = (tk1 - 100).ToString();
                        txt7.Text = vagon7.ToString();
                        pictureBox17.Visible = true;
                        pictureBox7.Visible = false;

                    }
                    if (tk1 - 200 < 100 && tk1 > 200)
                    {
                        listBox7.AllowDrop = false;
                        listBox8.AllowDrop = false;
                        listBox9.AllowDrop = true;
                        listBox9.Items.Add(tk1 - 200);
                        vagonSayisi = 9;
                        txt9.Text = (tk1 - 200).ToString();
                        txt7.Text = vagon7.ToString();
                        txt8.Text = vagon8.ToString();
                        pictureBox17.Visible = true;
                        pictureBox7.Visible = false;
                        pictureBox18.Visible = true;
                        pictureBox8.Visible = false;
                    }
                    if (tk1 - 300 < 100 && tk1 > 300)
                    {
                        listBox7.AllowDrop = false;
                        listBox8.AllowDrop = false;
                        listBox9.AllowDrop = false;
                        listBox10.AllowDrop = true;
                        listBox10.Items.Add(tk1 - 300);
                        vagonSayisi = 10;
                        txt10.Text = (tk1 - 300).ToString();
                        txt7.Text = vagon7.ToString();
                        txt8.Text = vagon8.ToString();
                        txt9.Text = vagon9.ToString();
                        pictureBox17.Visible = true;
                        pictureBox7.Visible = false;
                        pictureBox18.Visible = true;
                        pictureBox8.Visible = false;
                        pictureBox19.Visible = true;
                        pictureBox9.Visible = false;


                    }
                }
                catch (Exception)
                {
                    MessageBox.Show("1.trayda hata var");
                }
            }
            catch (Exception)
            {

                MessageBox.Show("Bir hata olustu");
            }


        
        }
        private void listBox8_DragDrop(object sender, DragEventArgs e)
        {
            DataGridViewSelectedRowCollection rows = (DataGridViewSelectedRowCollection)e.Data.GetData(typeof(DataGridViewSelectedRowCollection));

            foreach (DataGridViewRow row in rows)
            {
                listBox8.Items.Add(row.Cells[10].Value);
                //dataGridView1.Rows.Remove(row); griddeki veriyi silmeyelim   
            }
            double toplam = 0;
            //double renk;
            double[] topla = new double[listBox8.Items.Count];
            for (int i = 0; i < listBox8.Items.Count; i++)
            {
                topla[i] = Convert.ToDouble(listBox8.Items[i].ToString());
                toplam = toplam + topla[i];
            }
            tk1 = toplam;
            txt8.Text = tk1.ToString();
           // y8.Text = "%" + tk1.ToString();
            try
            {
                if (tk1 >= 300)
                {
                    MessageBox.Show("Yeterli Vagon Yok");
                    return;
                }
                try
                {
                    if (tk1 >= 100)
                    {

                        txt8.Text = vagon8.ToString();
                    }

                    if (tk1 - 100 < 100 && tk1 > 100)
                    {
                        listBox8.AllowDrop = false;
                        listBox9.AllowDrop = true;
                        listBox9.Items.Add(tk1 - 100);
                        vagonSayisi = 9;
                        txt9.Text = (tk1 - 100).ToString();
                        txt8.Text = vagon7.ToString();
                        pictureBox18.Visible = true;
                        pictureBox8.Visible = false;

                    }
                    if (tk1 - 200 < 100 && tk1 > 200)
                    {
                        listBox9.AllowDrop = false;
                        listBox10.AllowDrop = true;
                        listBox10.Items.Add(tk1 - 200);
                        vagonSayisi = 10;
                        txt10.Text = (tk1 - 200).ToString();

                        txt8.Text = vagon8.ToString();
                        txt9.Text = vagon9.ToString();
                        pictureBox19.Visible = true;
                        pictureBox9.Visible = false;
                    }
                }
                catch (Exception)
                {

                    MessageBox.Show("1.trayda hata var");
                }
            }
            catch (Exception)
            {

                MessageBox.Show("bir hata olustu");
            }

          
        }

        private void listBox9_DragDrop(object sender, DragEventArgs e)
        {
            DataGridViewSelectedRowCollection rows = (DataGridViewSelectedRowCollection)e.Data.GetData(typeof(DataGridViewSelectedRowCollection));

            foreach (DataGridViewRow row in rows)
            {
                listBox9.Items.Add(row.Cells[10].Value);
               
                //dataGridView1.Rows.Remove(row); griddeki veriyi silmeyelim   
            }
            double toplam = 0;
            //double renk;
            double[] topla = new double[listBox9.Items.Count];
            for (int i = 0; i < listBox9.Items.Count; i++)
            {
                topla[i] = Convert.ToDouble(listBox9.Items[i].ToString());
                toplam = toplam + topla[i];
            }
            tk1 = toplam;
            txt9.Text = tk1.ToString();
           // y9.Text = "%" + tk1.ToString();
            try
            {
                if (tk1 >= 200)
                {
                    MessageBox.Show("Yeterli Vagon Yok");
                    return;
                }
                try
                {
                    if (tk1 >= 100)
                    {
                        txt9.Text = vagon9.ToString();
                    }

                    if (tk1 - 100 < 100 && tk1 > 100)
                    {
                        listBox9.AllowDrop = false;
                        listBox10.AllowDrop = true;
                        listBox10.Items.Add(tk1 - 100);
                        vagonSayisi = 10;
                        txt10.Text = (tk1 - 100).ToString();
                        txt9.Text = vagon9.ToString();
                        pictureBox19.Visible = true;
                        pictureBox9.Visible = false;
                    }
                }
                catch (Exception)
                {

                    MessageBox.Show("1.trayda hata var");
                }
            }
            catch (Exception)
            {

                MessageBox.Show("Bir hata olustu");
            }
          
      
        }

        private void listBox10_DragDrop(object sender, DragEventArgs e)
        {
            DataGridViewSelectedRowCollection rows = (DataGridViewSelectedRowCollection)e.Data.GetData(typeof(DataGridViewSelectedRowCollection));

            foreach (DataGridViewRow row in rows)
            {
                listBox10.Items.Add(row.Cells[10].Value);
                //dataGridView1.Rows.Remove(row); griddeki veriyi silmeyelim   
            }
            double toplam = 0;
            //double renk;
            double[] topla = new double[listBox10.Items.Count];
            for (int i = 0; i < listBox10.Items.Count; i++)
            {
                topla[i] = Convert.ToDouble(listBox10.Items[i].ToString());
                toplam = toplam + topla[i];
            }
            tk1 = toplam;
            txt10.Text = tk1.ToString();
            //y10.Text = "%" + tk1.ToString();
            try
            {
                if (tk1 >= 100)
                {

                   // txt10.Text = vagon10.ToString();
                    pictureBox20.Visible = true;
                    pictureBox10.Visible = false;
                    MessageBox.Show("Yeterli Vagon Yok!");

                    return;
                }   

            }
            catch (Exception)
            {

                MessageBox.Show("1.trayda hata var");
            }
        }

        private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        private void txt1_TextChanged(object sender, EventArgs e)
        {

        }

        private void btnÖnizleme_Click(object sender, EventArgs e)
        {
            OnizlemeForm of = new OnizlemeForm();
            of.Show();
            this.Hide();
        }

        private void btnIstekKaydet_Click(object sender, EventArgs e)
        {
          
            string tvsuresi;
   
            double saat;
            saat=Convert.ToDouble(txtMesafe.Text) / (double)(120-(vagonSayisi*3));
         
            tvsuresi=saat.ToString() + " saat ";
           




            try
            {
                if (con.State == ConnectionState.Closed)
                {
                    con.Open();
                }

                SqlCommand cmd = new SqlCommand("sp$VagonDoldur", con);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.AddWithValue("@LokomotifID", cb1.Text);
                cmd.Parameters.AddWithValue("@VagonA", txt1.Text);
                cmd.Parameters.AddWithValue("@VagonB", txt2.Text);
                cmd.Parameters.AddWithValue("@VagonC", txt3.Text);
                cmd.Parameters.AddWithValue("@VagonD", txt4.Text);
                cmd.Parameters.AddWithValue("@VagonE", txt5.Text);
                cmd.Parameters.AddWithValue("@VagonF", txt6.Text);
                cmd.Parameters.AddWithValue("@VagonG", txt7.Text);
                cmd.Parameters.AddWithValue("@VagonH", txt8.Text);
                cmd.Parameters.AddWithValue("@VagonJ", txt9.Text);
                cmd.Parameters.AddWithValue("@VagonK", txt10.Text);
                cmd.Parameters.AddWithValue("@TahminiVarisSuresi",tvsuresi);
               
          

                cmd.ExecuteNonQuery();
                MessageBox.Show("Onaylandı!");


            }
            catch (Exception)
            {

                MessageBox.Show("sp hatası");
            }
        }

        private void btnSil_Click(object sender, EventArgs e)
        {
            try
            {
                if (con.State == ConnectionState.Closed)
                {
                    con.Open();
                }

                SqlCommand cmd = new SqlCommand("sp$UyeİstekRed", con);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.AddWithValue("@UyeID", txtSil.Text);
              
                cmd.ExecuteNonQuery();
                gridyenileme();
                MessageBox.Show("Reddedildi!");


            }
            catch (Exception)
            {

                MessageBox.Show("Talep Reddi Gerçekleştirilemedi!");
            }
        }

        private void btnIslemler_Click(object sender, EventArgs e)
        {
            KislemleriForm k = new KislemleriForm();
            k.Show();
            this.Hide();
        }

        private void button1_Click_1(object sender, EventArgs e)
        {
            Anasayfa ana = new Anasayfa();
            ana.Show();
            this.Hide();
        }

        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {

        }

        private void dataGridView1_CellContentClick_1(object sender, DataGridViewCellEventArgs e)
        {
        
        }

        private void dataGridView1_MouseDown_1(object sender, MouseEventArgs e)
        {
            dataGridView1.DoDragDrop(dataGridView1.SelectedRows, DragDropEffects.Move);
        }
    }
}